package pt.isec.gpsgroup5.moneybox;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;

public class DbHelper extends SQLiteOpenHelper{
	
	//Static members
	public static final String DATABASE_NAME = "objectives.db";
	public static final int DATABASE_VERSION = 1;
	public static final String ID ="id";
	public static final String NAME ="nome";
	public static final String FINAL_AMOUNT ="final_amount";
	public static final String CURRENT_AMOUNT ="current_amount";
	public static final String PRIORITY ="priority";
	public static final String YEAR ="year";
	public static final String MONTH ="month";
	public static final String DAY ="day";
	public static final String STATUS ="status";
	public static final String TABLE_NAME ="objectives";
	public static final String DB_PATH = "/data/data/pt.isec.gpsgroup5.moneybox/databases/";
	private static final String DATABASE_CREATE = "create table "
			+ TABLE_NAME + " ( " 
			+ ID + " integer primary key autoincrement, " 
			+ NAME + " text not null, " 
			+ FINAL_AMOUNT + " text not null, "
			+ CURRENT_AMOUNT + " text not null, "
			+ PRIORITY +" text not null, " 
			+ YEAR +" text not null, " 
			+ MONTH +" text not null, " 
			+ DAY +" text not null, " 
			+ STATUS + " text not null );";
	
	 
	//Constructor
	public DbHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
	}
	
    public DbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    //Creates DB
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE); 
		
	}

	//Updates DB
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); 
        onCreate(db); 
		
	}
	
	

}
